﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Weight.Base;
using Weight.Model.ParamEntity;
using Weight.Model.TableEntity;
using Dapper;

namespace Weight.Dal.Contract
{
    public  class DalContractConsume
    {
        /// <summary>
        /// 查询充值记录
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        public IEnumerable<ContractTicketConsumeEntity> List(QueryContractConsumeReq req)
        {
            string sql = "select * from ContractTicketConsume where TicketId=@TicketId";
            if (!string.IsNullOrEmpty(req.PlateNum))
            {
                req.PlateNum = "%" + req.PlateNum + "%";
                sql += " and PlateNum like @PlateNum";
            }
            if (!string.IsNullOrEmpty(req.EndDate) && !string.IsNullOrEmpty(req.StartDate))
            {
                sql += " and Convert(DateTime,ConsumeTime)>=Convert(DateTime,@StartDate)";
                sql += " and Convert(DateTime,ConsumeTime)<=Convert(DateTime,@EndDate)";
            }
            sql += " order by   Convert(DateTime,ConsumeTime) desc ";
            using (IDbConnection conn = SessionFactory.CreateConnection())
            {
                return conn.Query<ContractTicketConsumeEntity>(sql, req);
            }
        }
    }
}
